//////////////////////////////////////////
//
//	FlexInc. 2011
//	http://www.loziosecchi.it/flex_inc
//	http://twitter.com/loziosecchi
//
//////////////////////////////////////////

package flexInc.spark.components
{	
	import mx.core.IVisualElement;
	import mx.managers.IFocusManagerComponent;
	
	import spark.components.supportClasses.ButtonBarBase;
	
	//--------------------------------------
	//  Other metadata
	//--------------------------------------
	
	[AccessibilityClass(implementation="spark.accessibility.TabBarAccImpl")]

	/**
	 * Because this component does not define a skin for the mobile theme, it is reccomended
	 * that you not use it in a mobile application. Alternatively, you
	 * can define your own mobile skin for the component. For more information,
	 * see <a href="http://help.adobe.com/en_US/Flex/4.0/UsingSDK/WS53116913-F952-4b21-831F-9DE85B647C8A.html">Spark Skinning</a>.
	 */
	[DiscouragedForProfile("mobileDevice")]
	
	//--------------------------------------
	//  Other metadata
	//--------------------------------------
	
	[IconFile("assets/icons/TagCloud.png")]

	/**
	 * This component lets you visualize a list of elements in a tag cloud.
	 */
	public class TagCloud extends ButtonBarBase implements IFocusManagerComponent
	{
		/**
		 * Constructor
		 */
		public function TagCloud()
		{
			super();
			
			requireSelection = false;
			mouseFocusEnabled = false;        
		}

		//--------------------------------------------------------------------------
		//
		//  public functions
		//
		//--------------------------------------------------------------------------

		/**
		 *  @private
		 */
		override public function updateRenderer(renderer:IVisualElement, itemIndex:int, data:Object):void
		{
			itemToSize(renderer, data);
			super.updateRenderer(renderer, itemIndex, data);
		}
		


		//--------------------------------------------------------------------------
		//
		//  protected/private functions
		//
		//--------------------------------------------------------------------------
		
		/**
		 * @private
		 */
		private function itemToSize(renderer:IVisualElement, data:Object):void
		{
			if(renderer is TagCloudButton && data is XML)
			{
				TagCloudButton(renderer).weight = Number(data.weight.text());				
			}else
			{
				TagCloudButton(renderer).weight = data.weight;				
			}
		}

		//--------------------------------------------------------------------------
		//
		//  Class mixins
		//
		//--------------------------------------------------------------------------
		
		/**
		 *  @private
		 *  Placeholder for mixin by TabBarAccImpl.
		 */
		protected static var createAccessibilityImplementation:Function;

		//--------------------------------------------------------------------------
		//
		//  Overridden methods
		//
		//--------------------------------------------------------------------------
		
		/**
		 *  @private
		 */
		override protected function initializeAccessibility():void
		{
			if (TagCloud.createAccessibilityImplementation != null)
				TagCloud.createAccessibilityImplementation(this);
		}
	}
}